﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;

namespace Imagine
{
    public class LevelEditor
    {
        int tileWidth = 32;
        int tileHeight = 32;
        LevelEditor()
        {}
        static LevelEditor instance;

        static public LevelEditor Instance()
        {
            if(instance == null)
                instance = new LevelEditor();

            return instance;
        }

        void PlaceTile(Vector2 position)
        {

        }
        public void Update()
        {

        }

        Vector2 GenerateXY(int index, int rows)
        {
            int rowNum = index/rows;
            int colNum = index%rows;

            return new Vector2(colNum,rowNum);
        }

        public void ReadTileMap(string tileMap)
        {
            string[] level = File.ReadAllLines(tileMap);
            int row = 0;
            //Parse the level string here
            foreach(string line in level)
            {
                for (int i = 0; i < line.Length; ++i)
                {
                    char ch = line[i];
                    switch (ch)
                    {
                        case '#':   //Place a tile here
                            {
                                SimplePhysicsSprite tile = new SimplePhysicsSprite("block");
                                tile.PhysicsSprite.Position = new Vector2(i * tileWidth, row * tileHeight);
                                tile.InitPhysics(eShapeType.Shape_Box);

               
                                TheWorld.Instance().Add(tile, 0);
                                break;
                            }
                    }
                }
                ++row;
            }
                      
        }

//---------------------------------------------------------------------------
    }
}
